package com.yellowpage.ndc.dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.dao.BaseDaoHibernateImpl;
import com.yellowpage.white.dao.QueryAssistantSQL;

import com.yellowpage.ndc.data.Listing;
import com.yellowpage.ndc.data.ManageRegion;

public class ManageRegionDaoImpl extends BaseDaoHibernateImpl<ManageRegion, Long> implements ManageRegionDao {

	public ManageRegionDaoImpl() {
		super(ManageRegion.class);
	}		
	
	public String getRegionCodeByRegionName(String regionName) {
		
		QueryAssistantSQL sqlAssistant = this.newQueryAssistantSQL(
				"select  mr.REGION_CODE " +
				"  from db_ndc.MANAGE_REGION mr " +
				"  WHERE mr.NAME = '" + regionName + "'" );
							 	
		
		List<Map> resultList = sqlAssistant.query(
				this.getConnection(), new HashMap());
		
		if(resultList.size() > 0){
			return (String)resultList.get(0).get("REGION_CODE");
		}
		
//		String queryString = "from ManageRegion r where r.name = '" + regionName + "'";
//		List regionList = getHibernateTemplate().find(queryString);
//		if (regionList.size() > 0) {
//			ManageRegion mr = (ManageRegion) regionList.get(0);
//			return mr.getRegionCode();
//		}
		
		return null;
	}
		

}	